package com.example.android_datagridviewapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.dataGridView.DataGridView;
import com.example.dataGridView.RecyclerviewAdapter;
import com.example.entity.SellerBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用示例
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DataGridView dataGridView = findViewById(R.id.data_gridview);
        dataGrandView(dataGridView);

    }

    // 初始化dataGrandView
    private void dataGrandView(DataGridView mDataGridView) {
        // 设置数据源
        List<SellerBean> dataSource = new ArrayList();
        dataSource.add(new SellerBean(1, "张三", 21, "female", "Sales", "manager", 100000D, "删除"));
        dataSource.add(new SellerBean(2, "李四", 22, "female", "Sales", "manager", 900000D, "删除"));
        dataSource.add(new SellerBean(3, "王五", 23, "female", "Sales", "manager", 800000D, "删除"));
        // 设置列数
        mDataGridView.setColunms(8);
        // 设置表头内容
        mDataGridView.setHeaderContent(new String[]{"序号", "姓名", "年龄", "性别", "部门", "职级", "销售额", "操作"});
        // 绑定字段
        mDataGridView.setFieldNames(new String[]{"index", "name", "age", "sex", "department", "rank", "sales", "operator"});
        // 每个column占比
        mDataGridView.setColunmWeight(new float[]{1, 2, 1, 1, 3, 1, 3, 1});
        // 每个单元格包含控件
        mDataGridView.setCellContentView(new Class[]{TextView.class, TextView.class, TextView.class, TextView.class, TextView.class, TextView.class, TextView.class, Button.class});
        // 是否可滑动
        mDataGridView.setSlidable(true);
        // 单行选中模式
        mDataGridView.setSelectedMode(1);
        // 启用翻页
        mDataGridView.setFlipOverEnable(true, 10, getSupportFragmentManager());
        // 设置数据源
        mDataGridView.setDataSource(dataSource);
        // 初始化表格
        mDataGridView.initDataGridView();
        // 自适应行高度
        int height = getWindowManager().getCurrentWindowMetrics().getBounds().height();
        mDataGridView.setZoomHeight(height,3120);
        /**
         * 设置点击翻页事件监听
         * type 翻页类型是上翻页还是下翻页
         * */
        mDataGridView.setOnSwitchPageNumberListener(new DataGridView.OnSwitchPageNumberListener() {
            @Override
            public void onClick(String type) {
              // 写你自己的代码，如调用数据库翻页
            }
        });


        /**
         * 设置跳转页面事件监听
         * number 跳转的页面号
         * */
        mDataGridView.setOnPageNumberViewOnClickListener(new DataGridView.PageNumberViewOnClickListener() {

            @Override
            public void onClick(int number) {

            }
        });

        /**
         * 设置下一页按钮事件监听
         * */

        mDataGridView.setFlipOverBtnOnClickListener(new DataGridView.FlipOverBtnOnClickListener() {

            @Override
            public void onClick(View v, int mPageNumber, int mPageItems) {

            }
        });
        /**
         * 设置单元格内容点击事件监听
         */
        mDataGridView.setOnItemCellContentClickListener(new RecyclerviewAdapter.OnItemCellContentClickListener() {
            @Override
            public void onClick(View v, int row, int column) {
            }
        });

        /**
         * 设置单元格本身控件点击事件监听
         **/
        mDataGridView.setOnItemCellClickListener(new RecyclerviewAdapter.OnItemCellClickListener() {
            @Override
            public void onClick(View v, int row, int column) {
                // 获取指定条数
                Object rowData = mDataGridView.getRowData(row);
            }
        });



    }
}